<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="12">
			<p-form-item label="容器交易单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'containerOrder', validatorRules.containerOrder]" placeholder="请输入容器交易单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="PN/SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'pnsn', validatorRules.pnsn]" placeholder="请输入PN/SN"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="交易类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'tradeType', validatorRules.tradeType]" placeholder="请输入交易类型"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="容器交易时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择容器交易时间" v-decorator="[ 'containerTime', validatorRules.containerTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="容器交易类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'containerType', validatorRules.containerType]" placeholder="请输入容器交易类型" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="原容器码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'containerRaw', validatorRules.containerRaw]" placeholder="请输入原容器码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="新容器码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'containerNew', validatorRules.containerNew]" placeholder="请输入新容器码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="原容器数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'containerRawqty', validatorRules.containerRawqty]" placeholder="请输入原容器数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="新容器数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'containerNewqty', validatorRules.containerNewqty]" placeholder="请输入新容器数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="地址码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'addressCode', validatorRules.addressCode]" placeholder="请输入地址码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['type', validatorRules.type]" :trigger-change="true" dictCode="mes_type" placeholder="请选择类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename"
						dest-fields="lineid,lineno,linename"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="线体名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工序工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mobillno', validatorRules.mobillno]" placeholder="请输入工序工单编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工序工单数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'moQty', validatorRules.moQty]" placeholder="请输入工序工单数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="组件编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'moduleno', validatorRules.moduleno]" placeholder="请输入组件编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="组件名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'moduleidname', validatorRules.moduleidname]" placeholder="请输入组件名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="需求数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'demandQty', validatorRules.demandQty]" placeholder="请输入需求数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="交接数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'connectQty', validatorRules.connectQty]" placeholder="请输入交接数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="操作人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-user-by-dep v-decorator="['empnoopt', validatorRules.empnoopt]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工站编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['workstationcode', validatorRules.workstationcode]"
						:trigger-change="true"
						org-fields="wpno,wpname"
						dest-fields="workstationcode,workstationname"
						code="mes_q_ba_station"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工站名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'workstationname', validatorRules.workstationname]" placeholder="请输入工站名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="id,mcode,mname,sprc,mexplain"
						dest-fields="mid,mcode,mname,sprc,mexplain"
						code="wms_cpinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入物料名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'sprc', validatorRules.sprc]" placeholder="请输入物料规格型号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesMfContainerBindingModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JSelectUserByDep,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        containerOrder:{},
        pnsn:{},
        tradeType:{},
        containerTime:{},
        containerType:{},
        containerRaw:{},
        containerNew:{},
        containerRawqty:{},
        containerNewqty:{},
        addressCode:{},
        type:{rules: [{ required: true, message: '请输入类型!' }]},
        lineno:{rules: [{ required: true, message: '请输入线体编码!' }]},
        linename:{},
        mobillno:{},
        moQty:{},
        moduleno:{},
        moduleidname:{},
        demandQty:{rules: [{ required: true, message: '请输入需求数量!' }]},
        connectQty:{rules: [{ required: true, message: '请输入交接数量!' }]},
        empnoopt:{rules: [{ required: true, message: '请输入操作人员!' }]},
        workstationcode:{rules: [{ required: true, message: '请输入工站编码!' }]},
        workstationname:{rules: [{ required: true, message: '请输入工站名称!' }]},
        mcode:{rules: [{ required: true, message: '请输入物料编码!' }]},
        mname:{},
        sprc:{},
        mexplain:{},
        },
        url: {
          add: '/mes-manufacture/auto/mesMfContainerBinding/add',
          edit: '/mes-manufacture/auto/mesMfContainerBinding/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'containerOrder','pnsn','tradeType','containerTime','containerType','containerRaw','containerNew','containerRawqty','containerNewqty','addressCode','type','lineno','linename','mobillno','moQty','moduleno','moduleidname','demandQty','connectQty','empnoopt','workstationcode','workstationname','mcode','mname','sprc','mexplain','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'containerOrder','pnsn','tradeType','containerTime','containerType','containerRaw','containerNew','containerRawqty','containerNewqty','addressCode','type','lineno','linename','mobillno','moQty','moduleno','moduleidname','demandQty','connectQty','empnoopt','workstationcode','workstationname','mcode','mname','sprc','mexplain','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>
